package ir.androidpspring;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
//import android.widget.TextView;
import android.widget.Toast;

public class SecondActivity extends Activity {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.x++;
		//MyApplication.mMsg2 = MyApplication.mMsg2.concat("create");
		setContentView(R.layout.main2);
		//TextView tv = new TextView(this);
        //tv.setText("Second Activity");
        //setContentView(tv);
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onCreate", duration);
	    toaster.show();  
    	
		
		final Button button = (Button) findViewById(R.id.button21);
		button.setOnClickListener(new OnClickListener() {
		    @Override
			public void onClick(View v) {
		        //Toast.makeText(SecondActivity.this, "Now Pausing: " + MyApplication.x, Toast.LENGTH_SHORT).show();
		        Intent myIntent = new Intent(SecondActivity.this, FirstActivity.class);
		        myIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
		        SecondActivity.this.startActivity(myIntent); 
		    }
		});
		final Button button2 = (Button) findViewById(R.id.button22);
		button2.setOnClickListener(new OnClickListener() {
		    @Override
			public void onClick(View v) {
		        //Toast.makeText(SecondActivity.this, "Now Exiting", Toast.LENGTH_SHORT).show();
		        MyApplication.x = 0;
		        finish();
		    }
		});
	}
	
	@Override
	protected void onStart(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onStart", duration);
	    toaster.show();  
    	super.onStart();
    }
	@Override
	protected void onRestart(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onRestart", duration);
	    toaster.show();
    	super.onRestart();
    }
	@Override
	protected void onResume(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onResume", duration);
	    toaster.show();
    	super.onResume();
    }
	@Override
	protected void onPause(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onPause", duration);
	    toaster.show();
    	super.onPause();
    }
	@Override
	protected void onStop(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onStop", duration);
	    toaster.show();
    	super.onStop();
    }
	@Override
	protected void onDestroy(){
		Context context = getApplicationContext();
    	int duration = Toast.LENGTH_SHORT;
    	Toast toaster = Toast.makeText(context, "2onDestroy", duration);
	    toaster.show();
	    super.onDestroy();
    }
}